package com.telsoft.adapter;

import com.telsoft.kqxs.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ImageAdapter extends BaseAdapter {
	private Context context;
	private final String[] mainValues;

	public ImageAdapter(Context context, String[] mainValues) {
		this.context = context;
		this.mainValues = mainValues;
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View gridView = null;

		if (convertView == null) {

			gridView = new View(context);

			gridView = inflater.inflate(R.layout.main_item, null);

			// set value into textview
			TextView textView = (TextView) gridView
					.findViewById(R.id.grid_item_label);
			textView.setText(mainValues[position]);

			// set image based on selected text
			ImageView imageView = (ImageView) gridView
					.findViewById(R.id.grid_item_image);

			switch (position) {
			case 0:
				imageView.setImageResource(R.drawable.ketquabutton);
				break;
			case 1:
				imageView.setImageResource(R.drawable.tuongthuatbutton);
				break;
			case 2:
				imageView.setImageResource(R.drawable.tracuubutton);
				break;
			case 3:
				imageView.setImageResource(R.drawable.soicaubutton);
				break;
			case 4:
				imageView.setImageResource(R.drawable.lotobutton);
				break;
			case 5:
				imageView.setImageResource(R.drawable.thongkebutton);
				break;
			case 6:
				imageView.setImageResource(R.drawable.chiasebutton);
				break;
			case 7:
				imageView.setImageResource(R.drawable.gamebutton);
				break;
			case 8:
				imageView.setImageResource(R.drawable.capnhatbutton);
				break;
			}
		} else {
			gridView = (View) convertView;
		}
		return gridView;
	}

	public int getCount() {
		return mainValues.length;
	}

	public Object getItem(int position) {
		return null;
	}

	public long getItemId(int position) {
		return 0;
	}

}
